package com.apps.MiniChat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Client extends Activity implements OnClickListener {
	   private Button connectButton;
	   private EditText ipAdress;
	   private EditText serverPort;
	   private String serverIpAddress = "";
	   private String port = "";

	   @Override
	   public void onCreate(Bundle savedInstanceState)  {
	      super.onCreate(savedInstanceState);
	      setContentView(R.layout.client);
	      connectButton = (Button) findViewById(R.id.clientConnectButton);
	      ipAdress = (EditText) findViewById(R.id.ipAdressText);
	      serverPort = (EditText) findViewById(R.id.serverPort);
	      serverPort.setText(Integer.toString(MenuChat.Port));
	      connectButton.setOnClickListener(this); 
	   }
	   
	   @Override
	   public void onClick(View v) {
	  	 
	  	 if(v.getId() == R.id.clientConnectButton)
	  	 {
		     serverIpAddress = ipAdress.getText().toString();
		     port = serverPort.getText().toString();
		     if (!serverIpAddress.equals("") && !port.equals("")) 
		     {
		  	   Intent socketIntent =  new Intent(getApplicationContext(),ChatRoom.class );
		  	   socketIntent.putExtra("IP", serverIpAddress);
		  	   socketIntent.putExtra("PORT", Integer.parseInt(port));
		  	   startActivity(socketIntent);  
		     }  
	  	 }
	   }
	}